/* GUI CONVERTED from rcauis.p (converter v1.75) Tue Apr 10 12:03:20 2001 */
/* rcauis.p  - Shipper auto create - Main program                             */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.4 $                                                         */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 9.1            CREATED: 04/01/00   BY: *N0B5* Vinay Nayak-Sujir  */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 09/05/00   BY: *N0R9* Mudit Mehta        */
/* $Revision: 1.4 $    BY: Jean Miller    DATE: 03/22/01 ECO: *P008*          */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

/* ************** Begin Translatable Strings Definitions *********** */

&SCOPED-DEFINE rcauis_p_1 "Consolidate Invoices"
/* MaxLen:40 Comment: translation same as in rcsois.p */

&SCOPED-DEFINE rcauis_p_2 "Post Invoice"
/* MaxLen:40 Comment: translation same as in rcsois.p */

&SCOPED-DEFINE rcauis_p_3 "Use Shipper Nbr for Inv Nbr"
/* MaxLen:40 Comment: translation same as in rcsois.p */

&SCOPED-DEFINE rcauis_p_4 "Confirmed/Failed"
/* MaxLen: 30 Comment: for a logical variable as true/false */

&SCOPED-DEFINE rcauis_p_7 "P/"
/* MaxLen:3 Comment: First letter of the translated word
for "Preshipper*/

&SCOPED-DEFINE rcauis_p_8 "Pre-Shippers/Shippers"
/* MaxLen: 30 Comment: translate as in rcshrp01.p */

&SCOPED-DEFINE rcauis_p_9 "Number"
/* MaxLen: 20 Comment: translate as in rcshrp01.p*/

&SCOPED-DEFINE rcauis_p_10 "Ship-From"
/* MaxLen: 20 Comment: translate as in rcshrp01.p */

&SCOPED-DEFINE rcauis_p_11 "Ship-To/Dock"
/* MaxLen: 20 Comment: translate as in rcshrp01.p */

&SCOPED-DEFINE rcauis_p_12 "Pre-Shipper/Shipper"
/* MaxLen: 30 Comment: translate as in rcshrp01.p */

&SCOPED-DEFINE rcauis_p_13 "Print Selection Only"
/* MaxLen:40 Comment: true - only prints, false - processes data */

&SCOPED-DEFINE rcauis_p_14 "Effective"
/* MaxLen:40 Comment: Effective date for financial purposes*/

/* ************** End Translatable Strings Definitions *********** */

define variable shippernum  like abs_id label {&rcauis_p_9} no-undo.
define variable shippernum1 like abs_id no-undo.
define variable shipfrom    like abs_shipfrom label {&rcauis_p_10} no-undo.
define variable shipfrom1   like abs_shipfrom no-undo.
define variable shipto      like abs_shipto label {&rcauis_p_11} no-undo.
define variable shipto1     like abs_shipto no-undo.
define variable range       as   character no-undo.
define variable range1      as   character no-undo.
define variable invmov      like abs_inv_mov no-undo.
define variable invmov1     like abs_inv_mov no-undo.

define variable pick_ship      like mfc_logical format {&rcauis_p_12}
                               label {&rcauis_p_8} initial false no-undo.
define variable ship_date      like so_ship_date no-undo.
define variable eff_date       as   date label {&rcauis_p_14} no-undo.
define variable shipper_processed_ok like mfc_logical
                                     format {&rcauis_p_4} no-undo.
define variable print_only     like mfc_logical label {&rcauis_p_13} no-undo.
define variable consol_inv     like mfc_logical label {&rcauis_p_1}  no-undo.
define variable post_inv       like mfc_logical label {&rcauis_p_2}  no-undo.
define variable shipnum_as_inv like mfc_logical label {&rcauis_p_3}  no-undo.
define variable preshipper     like mfc_logical format {&rcauis_p_7} no-undo.

define variable err_file      as character  no-undo.
define variable junk_file     as character  no-undo.
define variable errfile_created like mfc_logical no-undo.

define temp-table tt_message no-undo
   field tt_msg       as character
   field tt_type      as integer.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
shipfrom       colon 25
   shipfrom1      colon 52 label {t001.i}
   shipto         colon 25
   shipto1        colon 52 label {t001.i}
   shippernum     colon 25
   shippernum1    colon 52 label {t001.i}
   invmov         colon 25
   invmov1        colon 52 label {t001.i}
   pick_ship      colon 43 skip(1)
   post_inv       colon 43
   shipnum_as_inv colon 43
   consol_inv     colon 43 skip(1)
   ship_date      colon 43
   eff_date       colon 43 skip(1)
   print_only     colon 43
with frame a side-labels width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   preshipper no-label
   abs_id label {&rcauis_p_9}
   abs_shipfrom label {&rcauis_p_10}
   abs_shipto label {&rcauis_p_11}
   abs_inv_mov
   shipper_processed_ok no-label
with STREAM-IO /*GUI*/  frame succfail width 80 down.

/* SET EXTERNAL LABELS */
setFrameLabels(frame succfail:handle).

assign
   ship_date = today
   eff_date = today
   print_only = yes
   batchrun = yes.

/* Shipper control file settings */
run ip_get_ctrl_defaults.

/* Get names of files used to capture output */
run ip_gen_filenames
   (output err_file,
    output junk_file).

mainloop:
repeat:

   if shippernum1 = hi_char then shippernum1 = "".
   if shipto1 = hi_char then shipto1 = "".
   if shipfrom1 = hi_char then shipfrom1 = "".
   if invmov1 = hi_char then invmov1 = "".

   update
      shipfrom shipfrom1
      shipto shipto1
      shippernum shippernum1
      invmov invmov1
      pick_ship
      post_inv
      shipnum_as_inv
      consol_inv
      ship_date
      eff_date
      print_only
   with frame a.

   if shipnum_as_inv and
      not consol_inv
   then do:
      /* Consolidating is mandatory when using shipper number as invoice */
      {pxmsg.i &MSGNUM=5984 &ERRORLEVEL=3}
      next-prompt consol_inv.
      next mainloop.
   end.

   bcdparm = "".

   {mfquoter.i shipfrom}
   {mfquoter.i shipfrom1}
   {mfquoter.i shipto }
   {mfquoter.i shipto1}
   {mfquoter.i shippernum }
   {mfquoter.i shippernum1}
   {mfquoter.i invmov}
   {mfquoter.i invmov1}
   {mfquoter.i pick_ship}
   {mfquoter.i post_inv}
   {mfquoter.i shipnum_as_inv}
   {mfquoter.i consol_inv}
   {mfquoter.i ship_date}
   {mfquoter.i eff_date}
   {mfquoter.i print_only}

   if shipfrom1 = "" then shipfrom1 = hi_char.
   if shipto1 = "" then shipto1 = hi_char.
   if shippernum1 = "" then shippernum1 = hi_char.
   if invmov1 = "" then invmov1 = hi_char.

   /* output DESTINATION SELECTION */
   {gpselout.i &printType = "printer" &printWidth = 80
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedoutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.

   {mfphead.i}

   if pick_ship then
      assign
         range = "p" + shippernum
         range1 = "p" + shippernum1.
   else
      assign
         range = "s" + shippernum
         range1 = "s" + shippernum1.

   procloop:
   for each abs_mstr
   where abs_shipfrom >= shipfrom and
         abs_shipfrom <= shipfrom1 and
         abs_shipto >= shipto and abs_shipto <= shipto1 and
         abs_inv_mov >= invmov and abs_inv_mov <= invmov1 and
         abs_id >= range and abs_id <= range1
   no-lock break by abs_id:

      assign
         errfile_created = no
         shipper_processed_ok = no.

      procblock:
      do:
         if print_only then leave procblock.

         /* If it is confirmed already */
         if substring(abs_status,2,1) = "Y" then do:
            /* Shipper previously confirmed */
            run ip_msg (8146, 4).
            leave procblock.
         end.

         /* Since invoice # cannot be longer than 8 char So error if
         shipper num is > 8 and "Use shipper # as Invoice # is yes */
         if not pick_ship and /*i.e. it is "Shipper" */
            shipnum_as_inv and
            length(abs_id) > 9 /* length including the prefix "s" */
         then do:
            /* Shipper # too long to use shipper document as invoice */
            run ip_msg (5982, 4).
            leave procblock.
         end.

         {gprun.i ""rcauis01.p""
            "(input abs_shipfrom,
              input abs_id,
              input ship_date,
              input eff_date,
              input post_inv,
              input shipnum_as_inv,
              input consol_inv,
              input err_file,
              input junk_file,
              output shipper_processed_ok)"}

         /* Because control has been thru rcauis01.p, error file
          * must have been created */
         errfile_created = yes.

      end. /* procblock */

      /* Do the necessary printing */
      run ip_report
         (input recid(abs_mstr)).

   end. /* procloop */

   {mfrtrail.i}

end. /* mainloop */

os-delete value(err_file).
os-delete value(junk_file).

PROCEDURE ip_report:
/*--------------------------------------------------------------------
  Purpose:      Report results of processing the shipper/pre-shipper
  Parameters:   input abs_recid  - recid of the abs_mstr
  Notes:
---------------------------------------------------------------------*/
   define input parameter abs_recid as recid no-undo.

   define variable errornum as integer no-undo.
   define variable warnnum as integer no-undo.
   define variable infonum as integer no-undo.
   define variable msgtext as character no-undo.

   define buffer b_abs_mstr for abs_mstr.

   procblk:
   do for b_abs_mstr:

      for first b_abs_mstr
      where recid(b_abs_mstr) = abs_recid
      no-lock: end.

      preshipper = (abs_id begins "P").

      display
         preshipper
         substring(abs_id,2) @ abs_mstr.abs_id
         abs_shipfrom        @ abs_mstr.abs_shipfrom
         abs_shipto          @ abs_mstr.abs_shipto
         abs_inv_mov         @ abs_mstr.abs_inv_mov
         shipper_processed_ok when (not print_only)
      with frame succfail STREAM-IO /*GUI*/ .

      down with frame succfail.

      if not print_only then do:
         if errfile_created then do:
            /* Read the messages in the error file, save them in the
             * message temp-table. */
            {gprun.i ""edimerrp.p""
               "(input err_file,
                 input '',
                 input '',
                 input '',
                 input-output table tt_message,
                 input-output errornum,
                 input-output warnnum,
                 input-output infonum)"}
         end. /* if errfile_created */

         if can-find (first tt_message)
         then do:
            /* Messages generated during processing */
            {pxmsg.i &MSGNUM=8591 &ERRORLEVEL=1 &MSGBUFFER=msgtext}
            /* Remove trailing "." in the message */
            if substring(msgtext, length(msgtext),1) = "." then
               msgtext = substring(msgtext,1, length(msgtext) - 1).
            display
               msgtext format "x(65)"
            with no-label column 5 STREAM-IO /*GUI*/ .
         end.

         for each tt_message:
            display
               (if tt_type = 1 then
                  ""
               else
               if tt_type =2 then
                  getTermLabel("WARNING",8)
               else
                  getTermLabel("ERROR",8))
               tt_msg format "x(65)"
            with no-label column 5 STREAM-IO /*GUI*/ .
         end.

      end. /* if not print_only  */

   end. /* procblk */

   for each tt_message exclusive-lock:
      delete tt_message.
   end.

END PROCEDURE. /* ip_report */

PROCEDURE ip_get_ctrl_defaults:
/*--------------------------------------------------------------------
  Purpose:      Get defaults from the shipper control file, create
                record if it does not exist
  Parameters:   <None>
  Notes:
---------------------------------------------------------------------*/

   /* Create the control record if they do not exist */
   {gprun.i ""socrshc.p""}
   {gprun.i ""rcpma.p""}

   for first mfc_ctrl where mfc_field = "rcc_auto_post"
   no-lock: end.
   post_inv = mfc_logical.

   for first mfc_ctrl where mfc_field = "rcc_use_shipper"
   no-lock: end.
   shipnum_as_inv = mfc_logical.

   for first mfc_ctrl where mfc_field = "rcc_consolidate"
   no-lock: end.
   consol_inv = mfc_logical.

END PROCEDURE. /* ip_get_ctrl_defaults */

PROCEDURE ip_msg:
/*--------------------------------------------------------------------
  Purpose:      Message Processing routine
  Parameters:
       input:   i_num - error #
       input:   i_stat - severity of error, 1-info, 2-warn, 3&4-error
  Notes:
---------------------------------------------------------------------*/
   define input parameter i_num as integer no-undo.
   define input parameter i_stat as integer no-undo.

   define variable msgtext as character no-undo.

   /* To prevent the "Error" and "Warning" from being added,
    * we uses status 1. In tt_type save the correct status */
   {pxmsg.i &MSGNUM=i_num &ERRORLEVEL=1 &MSGBUFFER=msgtext}

   create tt_message.
   assign
      tt_msg = msgtext
      tt_type = i_stat.

   if recid(tt_message) = ? then.

END PROCEDURE. /* ip_msg */

PROCEDURE ip_gen_filenames:
/*--------------------------------------------------------------------
  Purpose:      Generate filenames
  Parameters:
      output:   err_file - filename capture output to be used later
      output:   junk_file - filename capture output to be discarded
  Notes:
---------------------------------------------------------------------*/
   define output parameter err_file as character no-undo.
   define output parameter junk_file as character no-undo.

   define variable file_prefix as character initial "tmp" no-undo.
   define variable file_ext as character initial ".qad" no-undo.

   err_file = file_prefix + string (time, "99999") + file_ext.
   junk_file = file_prefix + string (time + 1, "99999") + file_ext.

END PROCEDURE. /* ip_gen_filenames */
